package com.tcy.bigevent.service.impl;

import com.tcy.bigevent.mapper.CategoryMapper;
import com.tcy.bigevent.pojo.Category;
import com.tcy.bigevent.service.CategoryService;
import com.tcy.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    public List<Category> listAll()
    {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer)map.get("id");
        return categoryMapper.listAllByUserId(userId);
    }

    @Override
    public void add(Category category) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer)map.get("id");
        category.setCreateUser(userId);
        categoryMapper.add(category);
    }

    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public Category getById(Integer id) {
        return categoryMapper.getById(id);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
